//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#if !defined(__CSOCKET_H__)
#define __CSOCKET_H__

#define _NO_CSOCKET_CLASSOBJECT_
#include "_CSocket.h"
#include <elatypes.h>
#include <car.h>
//#include <sys/netmisc.h>

#define STATUS_WIN32_ERROR(u) ((ECode)((u)|0x80070000))
#define E_NOT_ENOUGH_MEMORY       STATUS_WIN32_ERROR(   8)

class CSocket : public _CSocket
{
public:

    CARAPI_(PInterface) Probe(
            /* [in] */ REIID riid);

    CARAPI_(UInt32) AddRef(void);

    CARAPI_(UInt32) Release(void);

    CARAPI Accept(
        /* [out] */ ISocket * * ppIncomingConnection,
        /* [out] */ SocketAddr * pAddress,
        /* [out] */ Int32 * pError);

    CARAPI Bind(
        /* [in] */ const SocketAddr & address,
        /* [out] */ Int32 * pError);

    CARAPI Connect(
        /* [in] */ const SocketAddr & address,
        /* [out] */ Int32 * pError);

    CARAPI GetPeerName(
        /* [out] */ SocketAddr * pAddress,
        /* [out] */ Int32 * pError);

    CARAPI GetSockName(
        /* [out] */ SocketAddr * pAddress,
        /* [out] */ Int32 * pError);

    CARAPI Listen(
        /* [in] */ Int32 backLog,
        /* [out] */ Int32 * pError);

    CARAPI Recv(
        /* [in] */ Flags32 flags,
        /* [in] */ Int32 bytesToRecv,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ Int32 * pError);

    CARAPI RecvFrom(
        /* [in] */ Flags32 flags,
        /* [in] */ Int32 bytesToRecv,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ SocketAddr* pSourceAddr,
        /* [out] */ Int32 * pError);

    CARAPI Send(
        /* [in] */ Flags32 flags,
        /* [in] */ const MemoryBuf & buffer,
        /* [out]*/ Int32 * bytesSent,
        /* [out] */ Int32 * pError);

    CARAPI SendTo(
        /* [in] */ Flags32 flags,
        /* [in] */ const MemoryBuf & buffer,
        /* [out]*/ Int32 * bytesSent,
        /* [in] */ const SocketAddr & targetAddr,
        /* [out] */ Int32 * pError);

    CARAPI Shutdown(
        /* [in] */ Int32 target,
        /* [out] */ Int32 * pError);

    CARAPI SetSockOpt(
        /* [in] */ Int32 level,
        /* [in] */ Int32 optName,
        /* [in] */ const MemoryBuf & optValue,
        /* [out] */ Int32 * pError);

    CARAPI GetSockOpt(
        /* [in] */ Int32 level,
        /* [in] */ Int32 optName,
        /* [in] */ Int32 optSize,
        /* [out] */ MemoryBuf * pOptValue,
        /* [out] */ Int32 * pError);

    CARAPI Ioctl(
        /* [in] */ Int32 command,
        /* [in] */ const MemoryBuf & inDataBuf,
        /* [out] */ MemoryBuf * pOutDataBuf,
        /* [out] */ Int32 * pError);

    CARAPI EventSelect(
        /* [in] */ IEvent * event,
        /* [in] */ Int32  eventMask);

//    CARAPI GetHostName(
//        /* [out] */ MemoryBuf * pName);

public:
    CSocket(unsigned int socket):m_socket(socket),m_cRef(0)
        {};

    int m_socket;
private:
    CSocket(){}
    Int32 m_cRef;
};

#endif //!(__CSOCKET_H__)

